
import rrd_base

def emit_navigation(f, time_frames):
    f.write('<table cellspacing="3" cellpadding="3"><tr>')
    for a_tf in time_frames.keys():
        f.write('<td><a href="{0}.html">{0}</a></td>'.format(a_tf))
    f.write('</tr></table>')

def doit(objects):
    for tf in rrd_base.graph_time_frames().keys():
        f = open("/tmp/rrd/graphs/{0}.html".format(tf), "w")
        f.write("<html>\n")
        f.write('<head><title>{0} Graphs</title></head>\n'.format(tf))
        f.write('<body>\n')
        f.write('<table>\n')

        f.write('<tr><td align="center">')
        emit_navigation(f, rrd_base.graph_time_frames())
        f.write('</td></tr>\n')

        for object in objects:
#            f.write('<tr><td><a href="{0}"><img src="{1}"></a></td></tr>\n'.format(object.rel_image_name(tf), object.rel_icon_name(tf)))
            f.write('<tr><td><a href="{0}"><img src="{1}"></a></td></tr>\n'.format(object.rel_image_name(tf), object.rel_image_name(tf)))

        f.write('<tr><td align="center">')
        emit_navigation(f, rrd_base.graph_time_frames())
        f.write('</td></tr>\n')

        f.write('</table>\n')

        f.write("</body></html>\n")
